package day16_513;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;

/**
 * @ClassName Solution
 * @Description TODO
 * @Author clockTown
 * @Date 2021/5/24 20:44
 * @Version 1.0
 */
public class Solution {
    public static int findBottomLeftValue(TreeNode root) {
        //q用来层序遍历
        Queue<TreeNode> q = new ArrayDeque<>();
        //res 记录最后一层第一个数
        int res = 0;

        q.add(root);
        while (!q.isEmpty()){
            int num = q.size();
            for (int i = 0; i < num; i++) {
                TreeNode node = q.remove();
                if (i == 0){
                    res = node.val;
                }
                if (node.left != null){
                    q.add(node.left);
                }
                if (node.right != null){
                    q.add(node.right);
                }
            }
        }
        return res;

    }

}
